<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTableUserMoneyCoupon extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_money_coupon_record', function (Blueprint $table) {
            $table->id();
            $table->string('coupon_name', 50)->default('')->comment('现金券名');
            $table->char('coupon_code', 10)->default('')->comment('现金券code');
            $table->tinyInteger('is_delete')->default(0)->comment('1删除 默认0');
            $table->tinyInteger('state')->default(1)->comment('1可用 0不可用 默认1');
            $table->bigInteger('user_id')->unsigned()->default(0)->comment('用户ID');
            $table->dateTime('start_time')->nullable(false)->comment('可用开始时间');
            $table->dateTime('end_time')->nullable(false)->comment('可用结束时间');
            $table->timestamps();
            $table->unique('coupon_code','uniq_coupon_code');
            $table->index(['coupon_code','start_time','end_time'], 'idx_coupon_code_start_end_time');
        });
        DB::statement('alter table ex_user_money_coupon_record comment "现金券发放记录表"');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_money_coupon_record');
    }
}
